﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;

namespace __ts.Core.Utilities
{
    /// <summary>
    /// 
    /// </summary>
    public static class Extension
    {
        public static string GetMatch(this string str, string pattern)
        {
            Match mh = Regex.Match(str, pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
            if (mh.Success)
            {
                return mh.Groups[1].Value;
            }
            return string.Empty;
        }

        public static string ReplaceMatch(this string str, string pattern, string newValue)
        {
            str = Regex.Replace(str, pattern, new MatchEvaluator(mh =>
            {
                if (mh.Success)
                {
                    return newValue;
                }
                return mh.Value;
            }));
            return string.Empty;
        }

    }
}
